home *** CD-ROM | disk | FTP | other *** search
- /* UPDATE . C
- #
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- g_jin@lbl.gov
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % Run time handlers to update picture, and file handling
- % Including:
- % Panel_init(), MapColor(), SetColormap(),
- % FileAccess(), LoadFile(), HistoHandle().
- %
- % The Panel_init() build a control panel for both color and
- % gray-scale interactive analyst.
- %
- % AUTHOR: Jin Guojun - LBL 4/1/1991
- */
-
- #ifndef ETAButtonColor
- #define ETAButtonColor 3
- #endif
-
- #include "tuner.h"
-
- #ifdef C_TUNER
- char *FRM[] = {"Red", "Green", "Blue", "Sync"};
- #else
- char *FRM[] = {" 0/000", "Frame", "Prev", "Next"};
- #endif
-
-
- Panel_init(parent, ela_scale, PBGcolor, map_panel)
- WinAttribute *parent;
- {
- char buf[128];
-
- sprintf(buf, "Elasitc TUNER and ANALYZER -- %d %s", ncolors,
- #ifdef C_TUNER
- "colors"
- #else
- "grey levels"
- #endif
- );
- Epanel = CreatePanel(100, 200, 512, 360, buf, parent,
- EnterWindowMask | LeaveWindowMask);
- XSetWindowBackground(parent->dpy, Epanel->win, PBGcolor);
- if (map_panel)
- XMapWindow(Epanel->dpy, Epanel->win);
-
- fontWidth = Epanel->font_w;
- fontHeight = Epanel->font_h;
-
- /* Quantization */
- QSlider = CreateSlider(Epanel, 192, 270, 5, -300, 100, 1, 0, "Quantizing", "",
- Blue, lightGray);
-
- #ifdef C_TUNER
- QButton = CreateButton(Epanel, 144, 261, 2, "Fixed Panel Color", NF,
- Visible, Light);
- fButton = CreateButton(Epanel, 64, 51, 4, "Channel", FRM, Visible, Light);
- QSlider->valid = False; /* never used, but easy. */
- ButtonState(QButton) = True; /* Change colors with image */
- #else
- QButton = CreateButton(Epanel, 16, 261, 2, "", NF, Visible, Light);
- fButton = CreateButton(Epanel, 16, 51, 4, "", FRM, Visible, Light);
- /* fButton = CreateButton(Epanel, 64, 51, 3, "Frame", FRM, Visible, Gray);*/
- strcpy(filelist[MENU3_LDFrm-1], "......"); /* invalid */
- #endif
-
- ESlider = CreateSlider(Epanel, 75, 174, ela_scale, -200*ela_scale, 200*ela_scale,
- 1, 0, "Tuner", "<- Gamma -> | <- S -> | <- Gamma ->", White, Visible);
- SetSBarRPos(ESlider, 0, 1);
- LSlider = CreateSlider(Epanel, 100, 174, 1, 0, 255, 2, 0, "Scale", "Linear",
- White, lightGray);
- DButton = CreateButton(Epanel, 50, 303, 2, "DATA", DUP, Visible, Light);
- /* clip control */
- CSlider = CreateSlider(Epanel, 312, 72, 2, 0, 254, 2, 0, "Clip", "",
- Blue, lightGray);
- SetSBarRPos(CSlider, 254, 2); /* init to no clip */
- Interpolate = CreateButton(Epanel, 420, 261, 2, "Interpolation", NF,
- Visible, Light);
- /* Other Buttons */
- ZButton = CreateButton(Epanel, 420, 204, 2, "ZERO", NF, Visible, Light);
- EButton = CreateButton(Epanel, 100, 204, 3, "Emphasis", BN1,
- lightGray, parent->dpy_depth==8 ? ETAButtonColor : Blue);
- RstButt = CreatePressButton(Epanel, 354, 300, "RESET", Gray);
- rfsButt = CreatePressButton(Epanel, 435, 300, "Refesh", Gray);
- FButton = CreateButton(Epanel, 16, 12, 3, "", BNF, Visible, Light);
- hButton = CreateButton(Epanel, 16, 96, 5, "", HST, Visible, Light);
- heqButt = CreatePressButton(Epanel, 435, 96, "histeq", Light);
- slider = LSlider; /* overlayed, init to linear */
- ButtonState(EButton) = ETALinear; /* init to linear */
- /* PULL DOWN MENU */
- ctrlmenu = CreatePopMenu(Epanel, parent, "Editer", ctrlist, numctrl);
- paramenu = CreatePopMenu(Epanel, parent, "SCALEs", paralist, numpara);
- filemenu = CreatePopMenu(Epanel, parent, "FILE", filelist, numcomd);
- fontmenu = CreatePopMenu(Epanel, parent, "Fonts", fontlist, numfont);
- NoteWin = CreatePanel(10, 10, 256, 128, "MESSAGE", parent, NULL);
- InfoWin = CreatePanel(10, 10, 512, 256, "Information", parent, NULL);
- MsgButton = CreateButton(NoteWin, 24, 16, 1, "", NOTEMSG, Visible, Gray);
- YesButt = CreatePressButton(NoteWin, 48, 80, " Yes ", Light);
- NoButt = CreatePressButton(NoteWin, 144, 80, " No ", Light);
- OkButt = CreatePressButton(NoteWin, 96, 80, " OK ", Light);
- AbortButt = CreatePressButton(NoteWin, 96, 80, " Abort ", Light);
-
- return map_panel;
- }
-
- /*===============================================
- % to reset original image parameter %
- ===============================================*/
- void
- ResetORange(img)
- Image *img;
- {
- register Mregister* mmm;
- if (img->setscale)
- mmm = &(img->mmm);
- else if (img->color_dpy)
- mmm = img->marray + img->fn%img->channels;
- else mmm = img->marray + img->fn;
- if (mmm->max < mmm->min || mmm->max < VCTEntry)
- mmm->max = MaxColors-1; /* never show small max value */
- SetSBarRPos(LSlider, img->linearlow=
- #ifdef DIRECT
- MAX(VCTEntry, mmm->min), 1);
- #else
- mmm->min, 1);
- #endif
- SetSBarRPos(LSlider, img->linearup=mmm->max, 2);
- if (slider==LSlider)
- DrawSlider(slider);
- }
-
-
- /* RETURNs: (-1) newfile; (n) reload n; (0) save, or errors for load */
-
- static char tbuf[128];
-
- FileAccess(imgp, max_num, noi) /* number of images in stack */
- Image *imgp[];
- {
- FILE* fp;
- char info[128], errinfos[32];
- register int i=0;
- bool state=i;
- struct stat statbuf;
- #define PCloseWin "Not enough memory. Press 'c' to close some image"
-
- if (ButtonState(FButton)==FileSave) {
- for (i=noi; i--;)
- if (imgp[i]->active) break;
- if (i<0) goto FDone; /* no active image */
- strcpy(tbuf, imgp[noi=i]->name); /* noi point to active image */
- if (imgp[noi]->frames > 1 &&
- YesOrNo("Save ALL frames ? YES/NO\n(NO, save current frame)",
- NoteWin->font_h)) {
- imgp[noi]->save_all = imgp[noi]->frames;
- } else imgp[noi]->save_all = imgp[noi]->frames<=1;
- PressButtonState(YesButt) = PressButtonState(NoButt) = RESETSTATE;
- }
- FRedo: DispInfo(Epanel, 0,
- "INPUT -- TAB to cat, BS to correct, ESC undo or TYPE new one", Yellow);
- if (state=TextLine(FButton, tbuf, sizeof(tbuf), 0, Exposure_handler, imgp, noi))
- switch (ButtonState(FButton)) {
- case FileLoad:
- if (noi >= max_num) {
- for (i=noi; i--;)
- if (strcmp(tbuf, imgp[i]->name)==0) break;
- if (i<0) {
- XBell(Epanel->dpy, state=0);
- WaitOk(NULL, PCloseWin, 0);
- break;
- }
- fsize = imgp[noi=i]->width*imgp[i]->height;
- }
- if (imgp[noi] && imgp[noi]->update) {
- sprintf(info, "save %s ? y/n", imgp[noi]->name);
- i = (strlen(info)+2) * Epanel->font_w;
- DispInfo(Epanel, 0, info, white1);
- info[0] = 0;
- TextLine(FButton, info, sizeof(info), i,
- Exposure_handler, imgp, noi);
- if (info[0] != 'n') {
- char sbuf[128];
- strcpy(sbuf, tbuf);
- ButtonState(FButton) = FileSave;
- FileAccess(imgp, max_num, noi+1);
- strcpy(tbuf, sbuf);
- }
- }
- sprintf(info, "Loading file %s", tbuf);
- DispInfo(Epanel, 0, info, Red);
- state = (int)(fp=freopen(tbuf, "rb", stdin));
- if (state) {
- if (state=LoadImage(fp, imgp+noi, tbuf))
- if (state>0) state = EOF;
- else /* < 0 */ state = noi;
- else sprintf(errinfos, "%s is wrong File", tbuf);
- }
- else sprintf(errinfos, "File not found");
- if (!state){
- DispInfo(Epanel, (strlen(info)+1)*Epanel->font_w,
- errinfos, Green);
- XBell(Epanel->dpy, state);
- WaitOk(NULL, errinfos, 0);
- }
- break;
- case FileSave:
- if (!stat(tbuf, &statbuf)) {
- TopWindow(Epanel, 0);
- DrawPanel(); XFlush(Epanel->dpy);
- sprintf(info, "file %s exist! overwrite ? y/n", tbuf);
- DispInfo(Epanel, 0, info, White);
- i = strlen(info);
- info[0] = 0;
- TextLine(FButton, info, 2, ++i*Epanel->font_w,
- Exposure_handler, imgp, noi);
- if (info[0] == Esc) break;
- if (info[0] != 'y') goto FRedo;
- }
- fp = freopen(tbuf, "wb", stdout);
- if (!fp){
- DispInfo(Epanel, 256, "can't open", Green);
- XBell(Epanel->dpy, state=0);
- WaitOk(NULL, sys_errlist[errno], 0);
- }
- else {
- imgp[noi]->OUT_FP = fp;
- if (imgp[noi]->o_type != RLE) {
- register Image* img=imgp[noi];
- register char *av[1];
- int frames = img->frames,
- save_info = img->pixmap_failed;
- i = img->save_all;
- if (!i) i++;
- img->frames = i;
- img->pxl_out = 1;
- img->o_form = IFMT_BYTE;
- ((U_IMAGE*)img)->update_header = (*img->header_handle)
- (HEADER_TO, img, 0, No);
- sprintf(info, "writing %s", tbuf);
- DispInfo(Epanel, 0, info, White);
- i = ReadSlider(ESlider, 1);
- sprintf(info, "%s ETA -f%d, bf=%d\n",
- Progname, i, img->curve);
- /* only output a sub-image when img is a single frame image */
- av[0] = info;
- (*img->header_handle)(HEADER_WRITE, img,
- 1, av, img->update);
- img->frames = frames;
- state=(*img->std_swif)(FI_SAVE_FILE, img, NULL,
- img->save_all ? 0 : img->fn);
- img->pixmap_failed = save_info;
- }
- else {
- register Image* img=imgp[noi];
- bool add_cmap=0, save_cur=0;
- if (img->dpy_channels==3 || !OsameI) {
- add_cmap = YesOrNo("apply screen color map ?", 0);
- PressButtonState(YesButt) =
- PressButtonState(NoButt) = RESETSTATE;
- if (img->channels == 3)/* don't save cmap */
- rle_dflt_hdr.ncmap = 0;
- }
- else if (img->cmaplen && img->in_cmap)
- regmap_to_rlemap(img->in_cmap, img->cmaplen,
- img->ncmap, &rle_dflt_hdr);
- save_cur = YesOrNo("save current setting ?", 0);
- PressButtonState(YesButt) =
- PressButtonState(NoButt) = RESETSTATE;
- memcpy(&cmn_hd, img, sizeof(cmn_hd));
- (*img->std_swif)(FI_DESC_ETA, &cmn_hd, info, cer);
- if (rle_dflt_hdr.comments)
- rle_dflt_hdr.comments[0] = str_save(cmn_hd.desc);
- sprintf(info, "writing %s", tbuf);
- DispInfo(Epanel, 0, info, White);
- state = (*img->std_swif)(FI_SAVE_FILE, img, add_cmap,
- save_cur ? lkt : NULL);
- }
- fclose(fp);
- }
- break;
- default: DispInfo(Epanel, 0, "???", Green);
- }
- FDone:
- ButtonState(FButton)=FileLabel;
- DrawButton(FButton);
- return state;
- }
-
-
- #ifdef DIRECT
-
- bool frmchange;
-
- #ifdef C_TUNER
-
- eta_scan_map(img, eta_map)
- Image *img;
- {
- int i_factor=get_iconsize(img, 0);
- byte *mp[3], *srcp[3];
- register int i, l, my;
-
- for (l=img->height; l--;) {
- mp[0] = SAVED_RLE_ROW(img, l);
- if (eta_map)
- srcp[0] = mp[0];
- else srcp[0] = ORIG_RLE_ROW(img, l);
- for (i=1; i<img->channels; i++)
- mp[i] = mp[i-1] + img->width,
- srcp[i] = srcp[i-1] + img->width;
- MapRGB(0, NULL, &img, srcp, mp, l, img->width, l, i_factor);
- }
- }
-
- MapColor(img, dp, fsize, colorp, start)
- Image *img;
- byte *dp;
- register XColor *colorp;
- {
- XColor TmpColor[MaxColors];
- int maxdiff=img->entries;
- register int i;
- register LKT *lktr=lkt, *lktg=lkt+MaxColors, *lktb=lkt+(MaxColors<<1);
- register XColor *tcp = TmpColor;
-
- if (maxdiff > ncolors)
- maxdiff = ncolors; /* limitation */
- else if (maxdiff < 2) return prgmerr(0, "map 0 colors");
-
- memcpy(tcp, colorp, sizeof(*tcp)*maxdiff);
- for (i=0; i<maxdiff; i++) {
- tcp[i].red = lktr[colorp[i].red>>8] << 8;
- tcp[i].green = lktg[colorp[i].green>>8] << 8;
- tcp[i].blue = lktb[colorp[i].blue>>8] << 8;
- }
- XStoreColors(img->dpy, img->colormap, tcp, maxdiff);/* load colors to VCT */
- XFlush(img->dpy);
- #ifdef _DEBUG_
- dumpColor(img->dpy, img->colormap, cquire);
- #endif
- }
-
- #else
-
- /*=======================================================
- % important note: Since lkt always invoked, so, %
- % even reset has to put min to lkt[0], not 0. %
- =======================================================*/
- MapColor(img, dp, fsize, colorp, start)
- Image *img;
- byte *dp;
- register XColor *colorp;
- {
- #ifdef _DEBUG_
- time_t t0, t1;
- time(&t0);
- #endif
-
- register int i;
- int maxdiff = img->marray[img->fn].max - start + 1;
-
- if (maxdiff < 1)
- maxdiff = 1;
- /* assign data to image buffer */
- img->image->data = (char *) dp;
-
- if (img->sub_img) {
- register int j, min=img->marray[img->fn].min;
- register LKT *lktp=lkt;
- register byte *rp = dp + img->sub_img_y * img->width + img->sub_img_x;
- for (i=0; i<img->sub_img_h; i++) {
- for (j=0; j<img->sub_img_w; j++)
- rp[j] = lktp[(rp[j] - min)&0xFF];
- XPutImage(img->dpy, img->win, img->gc, img->image,
- img->sub_img_x + img->x0, img->sub_img_y + i + img->y0,
- img->sub_img_x, img->sub_img_y + i, img->sub_img_w, 1);
- rp += img->width;
- }
- img->update = True;
- }
- else if (frmchange) {
- XPutImage(img->dpy, img->win, img->gc, img->image, 0, 0, 0, 0,
- img->width, img->height);
- frmchange=0;
- #ifdef _DEBUG_
- time(&t1);
- if (verbose) message("time=%d, start=%d, end=%d\n", t1-t0, start, i);
- #endif
- }
- else{
- for (i=start; i<maxdiff+start; i++) {
- register unsigned short illuminance, scale=65536 / ncolors;
- colorp[i].pixel = (u_long) i;
- illuminance = scale * lkt[i-start]; /* set i to high byte */
- colorp[i].red = colorp[i].green = colorp[i].blue = illuminance;
- colorp[i].flags = DoAll;
- }
- /* load colors to VCT */
- XStoreColors(img->dpy, img->colormap, colorp+start, maxdiff);
- }
- XFlush(img->dpy);
- #ifdef _DEBUG_
- dumpColor(img->dpy, img->colormap, cquire);
- #endif
- }
-
- #endif C_TUNER and Back_to COMMON_DIRECT
-
- Colormap
- SetColormap(wa, colorp, ncolors, newmap, VcTolerance)
- WinAttribute *wa;
- XColor colorp[];
- int ncolors;
- bool *newmap;
- {
- register i=XDisplayCells(wa->dpy, wa->screen);
- Colormap cmap = DefaultColormap(wa->dpy, wa->screen);
-
- if (wa->dpy_depth < 24) {
- if (ncolors > i)
- ncolors = i;
-
- mknew: message("NMap = %d\n", *newmap);
- if (*newmap) VCTEntry = 24;
-
- /* save first serveral entries for system */
- for (i=0; i < VCTEntry; i++) {
- colorp[i].pixel = i;
- XQueryColor(wa->dpy, cmap, &colorp[i]);
- }
- if (*newmap) {
- cmap = XCreateColormap(wa->dpy, wa->root, wa->visual, AllocAll);
- XStoreColors(wa->dpy, cmap, colorp, ncolors); /* load colors to VCT */
- }
- else{
- u_long pxl, plane_masks[8];
- /* number > 1 will get trouble. It is a bug. So take time do loop */
- for (i=VcTolerance; i<ncolors; i++)
- if (!XAllocColorCells(wa->dpy, cmap, 0, plane_masks, 0, &pxl, 1)
- && ncolors-i > 4) {
- register int j;
- long pxl[MaxColors];
- msg("can't alloc C_cell %d\n", i);
- i -= VcTolerance;
- for (j=0; j<i; j++)
- pxl[j] = colorp[j+VcTolerance].pixel;
- XFreeColors(wa->dpy, cmap, pxl, j, 0);
- --*newmap;
- goto mknew;
- }
- else colorp[i].pixel = pxl;
- XStoreColors(wa->dpy, cmap, colorp+VcTolerance, ncolors-VcTolerance);
- }
- if (*newmap && ncolors > 254 && arrow)
- XRecolorCursor(wa->dpy, arrow, colorp[255], colorp[254]);
- if (verbose)
- message("[%d] grey level %d\n", cmap, ncolors-VcTolerance);
- dumpColor(wa->dpy, cmap, cquire);
- XInstallColormap(wa->dpy, cmap);
- }
- return (wa->cmap=cmap);
- }
-
- #else /* B/W regular routines */
-
- Colormap
- SetColormap(wa, colorp, ncolors, newmap, DoQuant)
- WinAttribute *wa;
- XColor colorp[];
- int *ncolors;
- bool *newmap;
- {
- register i=XDisplayCells(wa->dpy, wa->screen);
- Colormap newcmap, cmap = DefaultColormap(wa->dpy, wa->screen);
-
- if (wa->dpy_depth < 24) {
- if (*ncolors > i)
- *ncolors = i;
-
- if (DoQuant){
- newcmap = XCopyColormapAndFree(wa->dpy, cmap);
- XFreeColormap(wa->dpy, newcmap);
- *newmap = 0;
- }
- if (*newmap && wa->dpy_depth < 24) {
- cmap = XCreateColormap(wa->dpy, wa->root, wa->visual, AllocAll);
- XStoreColors(wa->dpy, cmap, colorp, *ncolors);/* load VCT colors */
- XInstallColormap(wa->dpy, cmap);
- if (*ncolors > 254 && arrow)
- XRecolorCursor(wa->dpy, arrow, colorp[255], colorp[254]);
- } else {
- for (i=0; i < *ncolors; i++) {
- if (!XAllocColor(wa->dpy, cmap, &colorp[i])){
- if((colorp[i].pixel=GetCloseColor(wa->dpy, cmap, *ncolors,
- colorp[i].red>>8, colorp[i].green>>8, colorp[i].blue>>8))
- >0) continue;
- if (*ncolors-i < *ncolors>>ToleranceFactor+1){
- for (i++; i<*ncolors; i++)
- colorp[i].pixel = colorp[i-1].pixel;
- break;
- }
- /* free allocated entries in cmap */
- newcmap = XCopyColormapAndFree(wa->dpy, cmap);
- XFreeColormap(wa->dpy, newcmap);
- *ncolors >>= 1+quant;
- *ncolors = CreateCLT(colorp, *ncolors, DoAll, quant, True, &histinfo);
- msg("try to make %d level color map\n", *ncolors);
- i = -1; /* redo */
- }
- }
- }
- dumpColor(wa->dpy, cmap, cquire);
- }
- return (wa->cmap=cmap);
- }
-
- MapColor(img, rp, fsize)
- Image *img;
- register byte *rp;
- register int fsize;
- {
- register byte *bp=img->img_buf;
- XColor *color = graylevel;
- register int i, min=img->marray[img->fn].min;
- register LKT *lktp=lkt;
- int w=img->width;
- #ifdef EXTENDED_COLOR
- int i_fact = get_iconsize(img, 0);
- byte *scan =
- # ifdef USE_LAST_LINE
- bp + img->image->bytes_per_line*img->height - w;
- # else
- nzalloc(w, 1, "no8_scan");
- # endif
- #endif
-
- if (img->sub_img) {
- register int j;
- rp += img->sub_img_y * w + img->sub_img_x;
- bp += img->sub_img_y * w + img->sub_img_x;
- for (i=0; i<img->sub_img_h; i++) {
- j = img->sub_img_w;
- if (img->dpy_depth==8)
- while (j--)
- bp[j] = color[dgt[lktp[(rp[j] - min)&0xFF]]].pixel;
- else {
- #ifdef EXTENDED_COLOR
- LineScan(rp, scan, color, lktp, j, min, img->dpy_depth!=1);
- Map_Scanline(img, &scan, &scan, img->sub_img_x, img->sub_img_y + i,
- img->sub_img_w, i_fact);
- #else
- goto npseud;
- #endif
- }
- XPutImage(img->dpy, img->win, img->gc, img->image,
- img->sub_img_x + img->x0, img->sub_img_y + i + img->y0,
- img->sub_img_x, img->sub_img_y + i, img->sub_img_w, 1);
- bp += w;
- rp += w;
- }
- } else {
- if (img->dpy_depth == 8)
- for (i=0; i<fsize; i++)
- bp[i] = color[dgt[lktp[(rp[i] - min)&0xFF]]].pixel;
- else
- #ifdef EXTENDED_COLOR
- for (i=0; i<img->height; i++, rp+=w) {
- LineScan(rp, scan, color, lktp, w, min, img->dpy_depth!=1);
- Map_Scanline(img, &scan, &scan, 0, i, w, i_fact);
- }
- #else
- npseud: prgmerr(DEBUGANY, "system is not compiled with non-PSEUDO color");
- #endif
- /* Time Consuming Work */
- XPutImage(img->dpy, img->win, img->gc, img->image, img->x0, img->y0,
- 0, 0, w, img->height);
- }
- #if defined EXTENDED_COLOR && !defined USE_LAST_LINE
- free(scan);
- #endif
- }
-
- #endif DIRECT
-
-
-
- #ifdef C_TUNER
-
- LoadImage(fp, imgp, name)
- FILE *fp;
- image_information **imgp;
- char *name;
- {
- register int i;
- register byte *dp;
- int state = FileLoad;
- image_information *img = *imgp;
-
- if (img) {
- MType map_index[MaxColors];
- free(img->scan_data);
- for (i=0; i<img->entries; i++)
- map_index[i] = graylevel[i].pixel;
- if (img->hist) {
- register int* hp=img->hist;
- for (i=HistoSize*img->img_channels; i--;)
- hp[i] = 0;
- XFreeColors(img->dpy, img->colormap, map_index, i, 0);
- }
- DestroyColorImage(img);
- firstmap = 0;
- img->name = str_save(name);
- state = FileReLoad;
- }
- else img = *imgp = zalloc(1, sizeof(*img), "rle-img");
-
- init_img_info(img, Dpy, RLE, cmn_hd.color_dpy);
- img->IN_FP = fp;
- rw_set = False; /* reset user color table. */
- init_img_flag(img);
- img->name = name;
-
- #ifdef _DEBUG_
- message("marray=%u, img=%u\n", img->marray, img);
- #endif
- if ((i = get_pic(multi_hd=0, "", NULL, imgp, MGray)) < 0)
- return 0;
-
- /*==============================*
- * it also sets fsize *
- *==============================*/
- if (!Find_min_max(img, histinfo.histp=img->hist, img->data, Yes, 0))
- return state; /* no tuner can be performed */
- if (fButton) {
- img->RGB = ButtonState(fButton) = ButtonSync;
- img->setscale = ButtonState(hButton)==HistScaleSet;
- img->update = ButtonState(DButton) =DataAnalys;
- ChangeSlider(img, &slider, ESlider, LSlider, heqButt, EButton);
- ResetORange(img);
- DrawPanel();
- }
- img->curve = ETALinear;
- new_curve(lkt, histinfo, img->marray, img->curve, 0, img, img->w*img->h);
-
- message("%s is %d(r) x %d(c) x %d(n) -- %d\n",
- name, img->h, img->w, img->img_num, fsize);
-
- if (img->dpy_depth < 24)
- MapColor(img, img->scan_data, fsize,
- graylevel, MAX(VCTEntry, img->marray[img->RGB%3].min));
- HistoHandle(img, &histinfo, Yellow);
- return state;
- }
-
-
- CreateColorTuner(dpy, dpy1, img, create_panel, map_panel, set_gray)
- Display *dpy, *dpy1;
- image_information *img;
- {
- static cct_set, cct;
- if (!cct_set++) {
- Set_Monitor(Monitor, dpy, dpy1, img->colormap);
- VCTEntry = GetVctEntry(Dpy, Screen, Monitor[0].cmap, set_gray);
- Light = GetGray(dpy, img->colormap, ncolors, 224);
- }
- if (create_panel && !cct++) {
- I_ED.copy = nzalloc(sizeof(*I_ED.copy), 1, "I_copy");
- map_panel = CreateTuner(img, 5, darkGray, map_panel);
- img->curve = ETALinear;
- }
- return create_panel;
- }
-
- #else /* B-W handlers */
-
- LoadImage(fp, imgf, name)
- FILE* fp;
- Image **imgf; /* must be a double pointer */
- char *name;
- {
- int frames=(*imgf) ? (*imgf)->frames : 0, state=FileReLoad;
- register int i;
- register Image *img;
-
- cursor = XCreateFontCursor(Dpy, XC_umbrella);
-
- cmn_hd.IN_FP = fp; cmn_hd.in_type = IMAGE_INIT_TYPE;
- if ((*cmn_hd.header_handle)(HEADER_READ, &cmn_hd, 0, 0, False))
- return False;
-
- if (cmn_hd.in_form != IFMT_BYTE && !WaitOk(cmn_hd.frames & -8 ? AbortButt : 0,
- "images isn't in byte format", 0)) return False;
-
- cmn_hd.o_form = IFMT_BYTE;
- cmn_hd.pxl_out = 1;
-
- if (fsize*frames != row*cln*frm) {
- if (*imgf && (*imgf)->win) {
- DestroyImage(*imgf);
- state = FileReLoad;
- }
- else state = FileLoad;
- BuildImage(imgf, name, cln, row, frames!=frm ? frm : 0,
- cmn_hd.in_type, HIPS, IBNeed);
- cmn_hd.data = NULL;
- }
- else cmn_hd.data = (*imgf)->data;
-
- img = *imgf;
- histinfo.histp = img->hist;
- img->colormap = Monitor[0].cmap;
- img->channels = img->dpy_channels = 1;
- img->history = cmn_hd.history;
- cmn_hd.parts = img->parts;
- cmn_hd.stack_num = img->stack_num;
- memcpy(&img->superimpose, &cmn_hd.superimpose, 6 + 11*sizeof(int));
- if (cmn_hd.desc)
- img->desc = str_save(cmn_hd.desc);
- #ifdef _DEBUG_
- message("buf=%u, marray=%u, img=%u\n", img->data, img->marray, img);
- #endif
-
- fsize = img->width * img->height;
- cmn_hd.load_all = img->frames = frm;
- (cmn_hd.std_swif)(FI_LOAD_FILE, &cmn_hd, 0, 0, False);
- fclose(fp); (*imgf)->data = cmn_hd.data;
-
- /*===============================================================
- % compute the min, max, if allocating img->hist here, %
- % scale Global hist to img->hist + HistoSize*i %
- % after histogram return. (using for loop HistoSize times %
- % for loop do checking first and finish 0 out with i = -1 %
- ===============================================================*/
- for (i=img->frames; i--;) {
- register byte *dp=img->data + i * fsize;
- img->fn = i;
- Find_min_max(img, histinfo.histp, dp, Yes, True);
- #ifdef DIRECT
- {
- register int j;
- for (j=0; j<fsize; j++, dp++)
- if (*dp < VCTEntry) *dp = VCTEntry;
- }
- #endif
- }
-
- i = img->fn; /* keep 0 all the way to the end */
- img->mmm = img->marray[i];
- SetSBarRPos(LSlider, img->linearlow=img->mmm.min, 1);
- SetSBarRPos(LSlider, img->linearup=img->mmm.max, 2);
- img->curve = ETALinear;
- img->setscale = ButtonState(hButton)==HistScaleSet;
- img->update = ButtonState(DButton) = DataAnalys;
- DrawButton(DButton);
- ChangeSlider(img, &slider, ESlider, LSlider, heqButt, EButton);
- SetShowFramePos(img, fButton, i);
- ResetORange(img);
- new_curve(lkt, &histinfo, img->marray, img->curve, 0, img, fsize);
-
- message("%s is %d(r) x %d(c) x %d(f) -- %d [%d channels]\n",
- name, row, cln, frm, fsize*frm, img->channels);
-
- MapColor(img, img->data, fsize
- #ifdef DIRECT
- , graylevel, MAX(VCTEntry, img->marray[i].min)
- #endif
- );
-
- img->mmm = img->marray[i];
- HistoHandle(img, &histinfo, lightGray);
-
- /* select events to wait for. STRANGE ? this is not always useful */
- XSelectInput(img->dpy, img->win, I_Mask | KeyPressMask |
- StructureNotifyMask /*| ResizeRedirectMask*/);
- XSelectInput(img->dpy, img->icon, ExposureMask | StructureNotifyMask);
- return state;
- }
-
- #endif C_TUNER
-
-
- ToImageStr(img, fcolor, sub_w, fh, x0, y0)
- Image *img;
- register int fcolor;
- {
- register int h, y, xw, w=img->width;
- XImage *ximg = XGetImage(img->dpy, img->win, x0, y0, sub_w, h=fh,
- AllPlanes, img->image->format);
- register byte *px = (byte *) ximg->data;
- byte *p[3], *scan[3];
- int ff=get_iconsize(img, 0), pxw=ximg->bytes_per_line;
- long mask24 = 0xFFFFFF;
- if (img->dpy_depth > 8) {
- pxw <<= 2;
- fcolor = (fnt_b << 16) & (fnt_g << 8) & fnt_r;
- if (ImageByteOrder(img->dpy) != LSBFirst)
- mask24 <<= 8;
- }
- x0 += img->x0; y = (y0 += img->y0);
-
- if (img->dpy_channels==1) {
- register byte *pi = p[0] = img->data + y*w + x0;
- scan[0] = (img->color_dpy ? img->scan_data : (byte*)img->image->data)
- + y*w + x0;
- for (; h--; p[0]=(pi+=w), px+=pxw, scan[0]+=w) {
- for (xw=sub_w; xw--;) {
- if (img->dpy_depth > 8) {
- if (((int*)px)[xw] & mask24 != fcolor)
- continue;
- } else if (px[xw] != fcolor) continue;
- pi[xw] = fcolor;
- }
- # ifdef C_TUNER
- Map_Scanline(img, p, scan, x0, y++, sub_w, ff);
- # else
- memcpy(scan[0], px, sub_w);
- # endif
- }
- } else {
- p[0] = img->data + w*img->dpy_channels*y + x0;
- scan[2] = img->scan_data + w*(img->dpy_channels*y-1) + x0;
- for (; h--; px+=pxw, p[0]+=w*img->dpy_channels) {
- p[1] = p[0] + w;
- p[2] = p[1] + w;
- for (xw=sub_w; xw--;) {
- if (img->dpy_depth > 8) {
- if (((int*)px)[xw] & mask24 != fcolor)
- continue;
- } else if (px[xw] != fcolor) continue;
- p[0][xw] = fnt_r;
- p[1][xw] = fnt_g;
- p[2][xw] = fnt_b;
- }
- # ifdef C_TUNER
- scan[0] = scan[2] + w;
- scan[1] = scan[0] + w;
- scan[2] = scan[1] + w;
- Map_Scanline(img, p, scan, x0, y++, sub_w, ff);
- # endif
- }
- }
- PlaceArea(img, x0, y0, sub_w, fh);
- img->update = True;
- XDestroyImage(ximg);
- }
-
- char *DrawShape[]={" ", "Arc", "Line", "Rectangle"};
-
- DrawInImage(img, y0, emsg, buf)
- Image *img;
- int *y0;
- char *emsg, *buf;
- {
- Cursor dii_cursor=XCreateFontCursor(img->dpy, XC_crosshair);
- int b, lw=1, shape=DrawsLine, x, y, si=img->o_type==HIPS,
- color = AdoptColor(img, fnt_r, fnt_g, fnt_b, precision);
- if (!img->color_dpy) color >= 2;
- while(1) {
- XSetLineAttributes(img->dpy, img->gc, lw, 0, CapButt, 0);
- b = WaitButtonPress_n_InfoImage(img, &histinfo, y0, dii_cursor);
- RemoveImageEvent(img, ButtonAction) XBell(img->dpy, 0);
- if (b == Button3) break;
- if (b == Button2) {
- shape = ++shape & 3;
- if (!shape) {
- shape++;
- sprintf(buf, "line width = %d", lw);
- Get_Note_Input(buf, 16, 8, "width ", Green, 0);
- sscanf(buf, "%d", &lw);
- }
- DisplayMessage(NoteWin, DrawShape[shape], 4, 0);
- continue;
- }
-
- *y0 = SetParameterWin(img, img->event, img->font_h, 0);
- TrackSubWin(img, &histinfo, x=img->event->xbutton.x,
- y=img->event->xbutton.y, shape, Button1Mask, *y0);
- DisplayMessage(NoteWin, "press MIDDLE button to comfrim", 4, 0);
- b = WaitButtonPress_n_InfoImage(img, &histinfo, y0, dii_cursor)
- == Button2;
- XSetForeground(img->dpy, img->gc, color);
- Draws(img, 0, !b, img->sub_img);
- if (b) { /* comfirm */
- superimpose_add_elem(img, lw, color, shape, 0, 0, CapButt, 0);
- if (!si) embed_image(img, lw, color, x, y);
- img->update = True;
- }
- DisplayMessage(NoteWin, emsg, 4, img->sub_img=0);
- }
- XSetLineAttributes(img->dpy, img->gc, 0, 0, CapButt, 0);
- }
-
- AdoptColor(img, r, g, b, prec)
- Image *img;
- {
- register int c = img->color_form==CFM_SCF ? CloseColor_in_Map
- (img->in_cmap, img->cmaplen, r, g, b, prec) :
- (RED_to_GRAY * r + GREEN_to_GRAY * g + BLUE_to_GRAY * b) >> 8;
- TopWindow(img, 0);
- Exposure_handler(img->event, img);
- return c;
- }
-
- embed_image(img, lw, color, x, y)
- register U_IMAGE* img;
- register int x, y;
- {
- register int w=img->sub_img_w, h=img->sub_img_h;
- switch (img->sub_img) {
- case DrawsLine:
- if (w < 0) { x += w; w = -w; }
- if (h < 0) { y += h; h = -h; }
- break;
- case DrawsArc:
- x = img->sub_img_x - w;
- y = img->sub_img_y - h;
- h <<= 1; w <<= 1;
- break;
- case DrawsRect:
- if (x > img->sub_img_x)
- x = img->sub_img_x;
- if (y > img->sub_img_y)
- y = img->sub_img_y;
- }
- x -= lw; y -= lw;
- w += lw << 1; h += lw << 1;
- bound_check(w, x, img->width);
- bound_check(h, y, img->height);
- ToImageStr(img, color, w, h, x, y);
- }
-
- CombineImage_Draws(img, x, y, fnt_w, fnt_h, color)
- Image *img;
- register int x, y, fnt_w, fnt_h;
- {
- if (img->superimpose) {
- register superimpose_elems* sip=img->superimpose[1] + img->texts;
- fnt_w *= sip->cols; fnt_h *= sip->rows;
- }
- y -= img->ascent;
- if (fnt_w + x >= img->width)
- fnt_w = img->width - x - 1;
- if (fnt_h + y >= img->height)
- fnt_h = img->height - y - 1;
- ToImageStr(img, color, fnt_w, fnt_h, x, y);
- }
-